package com.bdth.bdthiss.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthiss.entity.Brands;
import com.bdth.bdthiss.mapper.BrandsMapper;
import com.bdth.bdthiss.service.BrandsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bdth.bdthiss.vo.Pagination;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LGP
 * @since 2020-04-28
 */
@Service
public class BrandsServiceImpl extends ServiceImpl<BrandsMapper, Brands> implements BrandsService {
    @Override
    public Page<Brands> listPages(Pagination pagination, Map<String, Object> query) {
        EntityWrapper<Brands> entityWrapper = new EntityWrapper<>();
        String name = (String)query.get("name");
        if(name!=null && !name.trim().equals(""))
            entityWrapper.like("name",name);
        if(pagination.getOrder()!=null) {
            if (pagination.getOrder().toLowerCase().equals("asc")){
                entityWrapper.orderBy(pagination.getSort(), true);
            }else{
                entityWrapper.orderBy(pagination.getSort(), false);
            }
        }
        Page<Brands> page = new Page<>(pagination.getPage()==null?1:pagination.getPage(),
                pagination.getRows()==null?20:pagination.getRows());

        List<Brands> items = baseMapper.selectPage(page,entityWrapper);
        page.setRecords(items);
        return page;
    }
}
